﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TrabiBT
{
    public partial class ViewVariableText : UserControl, IView
    {
        Variable myVar;
        object offset = (object)0;
        public ViewVariableText()
        {
            InitializeComponent();
        }

        public ViewVariableText(string name, string address, Variable var)
        {
            InitializeComponent();
            myVar = var;
            this.addressLabel.Text = address;
            this.nameLabel.Text = name;
        }

        private void ViewVariableText_Load(object sender, EventArgs e)
        {

        }

        public void UpdateD()
        {
            //valueLabel.Text = "AABB";
            if (myVar.CurrentValue != null)
            {
                if (myVar.Type == "float")
                {
                    float value = ((float)(myVar.CurrentValue));
                    valueLabel.Text = value.ToString();
                }
                else if (myVar.Type == "int32")
                {
                    float value = ((float)(myVar.CurrentValue));
                    valueLabel.Text =value.ToString();
                }
            }
            else
            {
                valueLabel.Text = "NA";
            }

        }

        private void showChartBtn_Click(object sender, EventArgs e)
        {
            ViewVariableChart chart = new ViewVariableChart(myVar);
            chart.Top = (chart.Height + 2) * App.Instance.MainForm.ChartCount;
            App.Instance.MainForm.PanelChart.Controls.Add(chart);
            myVar.AddView(chart);
            App.Instance.MainForm.ChartCount++;
        }

        private void resetBtn_Click(object sender, EventArgs e)
        {
            offset = myVar.CurrentValue;
        }

    }
}
